"""
Author: Anthony Salgado
Date: December 7, 2011
"""

import re
import allperms
import sys
from Dictionary import *


def main():
  d = Dictionary()
  print_all = False if '--valid' in sys.argv else True
  if '--i' in sys.argv:
    word = ''
    while word != 'quit()':
      word = raw_input('Enter a word or quit(): ')
      if word == 'quit()':
        print 'goodbye!'
        break
      if not print_all: print 'Valid permutations of',word + ':'
      else: print 'All permutations of', word + ':'
      perms = allperms.allperms(word)
      for perm in perms:
        if print_all or d.lookup(perm):
          print perm
  else:
    perms = allperms.allperms(sys.argv[1] if len(sys.argv) > 1 else 'racecar')
    for perm in perms:
      if d.lookup(perm) or print_all: print perm
  
if __name__ == '__main__':
  main()    
    
